package com.rh.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rh.controller.front.vo.CourseFrontVo;
import com.rh.controller.front.vo.CourseWebVo;
import com.rh.entity.CourseOrderVo;
import com.rh.entity.EduCourse;
import com.rh.entity.chapter.ChapterVo;
import com.rh.service.EduChapterService;
import com.rh.service.EduCourseService;
import com.rh.result.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author rh
 * 课程的前端管理
 */
@Api(tags = "课程前台管理")
@RestController
@RequestMapping("/eduservice/coursefront")
public class CourseFrontController {
    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduChapterService eduChapterService;

    /**
     * 条件查询带分页查询课程信息
     */
    @ApiOperation(value = "1.课程前台条件查询带分页")
    @PostMapping("getFrontCourseList/{page}/{limit}")
    public ResultVo getFrontCourseList(@PathVariable long page,
                                       @PathVariable long limit,
                                       @RequestBody(required = false) CourseFrontVo courseFrontVo){
    Page<EduCourse> coursePage=new Page<>(page,limit);
    Map<String,Object> map=eduCourseService.getCourseFrontList(coursePage,courseFrontVo);
    return ResultVo.ok().data(map);
    }
    /**
     * 查询课程详细
     */
    @ApiOperation(value = "2.课程前台详细页面")
    @GetMapping("getCourseFrontInfo/{courseId}")
    public ResultVo getCourseFrontInfo(@PathVariable String courseId){
        //根据课程id查询课程信息
        CourseWebVo courseWebVo=eduCourseService.getBaseCourseFrontInfo(courseId);
        //根据课程id查询章节和小节
        List<ChapterVo> chapterVoList = eduChapterService.getChapterVideoByCourseId(courseId);
        return ResultVo.ok().data("courseWebVo",courseWebVo).data("chapterVoList",chapterVoList);
    }
    /**
     * 根据课程id查询课程信息
     */
    @ApiOperation(value = "3.根据课程id查询课程信息")
    @PostMapping("getCourseInfoById/{id}")
    public CourseOrderVo getCourseInfo(@PathVariable String id){
        //根据id查询课程信息1
        CourseWebVo courseWebVo = eduCourseService.getBaseCourseFrontInfo(id);
        //把courseWebVo对象赋值给COurseOrderVo
        CourseOrderVo courseOrderVo = new CourseOrderVo();
        BeanUtils.copyProperties(courseWebVo,courseOrderVo);
        return courseOrderVo;
    }
}
